<template>
    <div class="moindex">
        <div class="navbar">
            <ul class="lstNav">
                <li
                    v-for = "(item,ind) in dicts.navs" :key="ind"
                    :class = "$route.path.indexOf(item.code)>0?'active':''"
                    @click="navitem(ind)"
                >
                    
                    <div class="item"><i :class="item.icon"></i> {{item.label}}</div>
                </li>
            </ul>
        </div>
        <div class="main">
            <router-view></router-view>
        </div>
    </div>
</template>

<script>
    import {admin} from '../../admin';
    import {moApp} from './moapp.js';
    export default {
        mounted(){
            var me = this;
            try {
                me.$nextTick().then(_=>{
                    return me.init();
                }).then(_=>{
                    return moApp.checkLocalUserInfo();
                }).then(loginResult=>{
                    if ( loginResult.status==1){
                        
                    me.$message.success('success')
                        me.refresh();
                    }
                    else{
                        var url ="/mo/login"
                        me.$router.push({
                            path: url
                        })
                    }
                })
            } catch (error) {
                console.log(error)
            }
        },
        data(){
            return{ 
                pageState:{
                    navIndex:0
                },
                pageStateKey : "zn_admin_mo_index",
                dicts:{
                    navs:[
                        {code:"main" , label:"主页" , icon:"fa fa-home"},
                        {code:"about" , label:"我的" , icon:"fa fa-user-o"}
                    ] ,

                }
            }

        },
        methods:{
            init(){
                var me = this;
                return new Promise((su,fa)=>{
                    try {
                        me.pageState = admin.api.getSessionObj( me.pageStateKey , me.pageState);  
                    } catch (error) {
                        console.log(error);
                        su();
                    }
                })
            },
            refresh(){
                var me = this;
                try {
                    
                } catch (error) {
                    console.log(error)
                }
            },
            navitem(navIndex){
                var me = this;
                try {
                    me.pageState.navIndex = navIndex;
                    admin.api.setSessionObj( me.pageStateKey , me.pageState); 
                    var url = "/mo/index/"+me.dicts.navs[me.pageState.navIndex].code;
                    me.$router.push({
                        path: url
                    })
                } catch (error) {
                    console.log(error)
                }
            },

        }
        
    }
</script>

<style lang="less" scoped>
    .moindex{
        .navbar{
            position: fixed;
            z-index: 999;
            width: 100%;
            bottom: 0;
            background-color: #fff;
            border-top: 1px solid #dcdfe6;
            ul.lstNav{
                display: flex;
                li{
                    flex: 1;
                    display: flex;
                    justify-content: space-around;
                    align-items: center;
                    .item{
                        height: 40px;
                        line-height: 40px;
                        text-align: center;
                    } 
                }
                li.active{
                    color: #0077fe;
                    border-top: 2px solid #0077fe;
                }
            }
        }
        .main{
            padding-bottom: 45px;
        }
    }
</style>